package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.mapper.SetmealMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 根据状态查询 套餐信息
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result selectByPage(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult= setmealService.selectByPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping
    public Result insertByList(@RequestBody SetmealDTO setmealDTO){

        return setmealService.insertByList(setmealDTO);
    }

    /**
     * 修改状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result selectByStatus(@PathVariable Integer status,Integer id){
        setmealService.updateByStatus(status,id);
        return Result.success();
    }

    /**
     * 删除套餐 时 还需要删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids){
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 进行套餐回显操作
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id){
        return Result.success(setmealService.selectByid(id));
    }

    @PutMapping
    public Result uptByList(@RequestBody SetmealDTO setmealDTO){
        setmealService.putByList(setmealDTO);
        return Result.success();
    }

}
